package com.teckteam.ptvsystem.model;

import java.util.Iterator;
import java.util.LinkedHashMap;

import com.teckteam.ptvsystem.model.facade.PTVConstants;

/**
 * Train Line representation.
 * 
 */
public class TrainLine extends AbstractRoute
{
   
   private String direction;
   
   public TrainLine(LinkedHashMap<String, String[]> inputList)
   {
      super(inputList);
      
      setTransportType("Train");
      setDirection(inputList.get("routeHeader")[2].charAt(0));
      setTimetablePeriod(inputList.get("routeHeader")[1]);
      
      //System.out.println("DEBUG: Creating " + this.toString());
   }
   
   protected void createStops(LinkedHashMap<String, String[]> inputList)
   {
      LinkedHashMap<String, AbstractStop> stopList = new LinkedHashMap<String, AbstractStop>();
      
      Iterator<String> iterator = inputList.keySet().iterator();
      
      // Step through and add every single train station retrieved
      while (iterator.hasNext())
      {
         String s = iterator.next();
         
         //handle routeHeader and ampmCols
         if (s.compareTo("routeHeader") == 0 || s.compareTo("ampmCols") == 0)
         {
            if(s.compareTo("ampmCols")==0)
               saveAmPmCols(inputList.get(s));
               
            continue;
         }
         stopList.put(s, new TrainStation(inputList.get(s), s, getDirectionFlag()));
         //stopList.get(s).setName(s);
      }
      
      setStops(stopList);
   }

   protected void setTimetablePeriod(String period)
   {
      if (period.compareTo(PTVConstants.TIMETABLE_MONFRI) == 0)
         super.setTimetablePeriod("Mon - Fri");
      else if (period.compareTo(PTVConstants.TIMETABLE_SAT) == 0)
         super.setTimetablePeriod("Saturday");
      else if (period.compareTo(PTVConstants.TIMETABLE_SUN) == 0)
         super.setTimetablePeriod("Sunday");
   }
}
